import  jieba
import numpy as np
import wordcloud
from PIL import Image
from matplotlib import pyplot as plt
from wordcloud import WordCloud

# word = jieba.cut('我爱北京天安门')
# for i in word:
#     print(i)
with open('停用词.txt', 'r', encoding='utf-8') as f:  #
    stopword_list = [word.strip('\n') for word in f.readlines()]
text = open('2021热搜.txt','r',encoding='utf-8').read()
words = jieba.cut(text)
text_words=[]
for word in words:
    if len(word)>=2:
        if word not in stopword_list:
            text_words.append(word)

from collections import  Counter

result = Counter(text_words).most_common(50)
print(result)

content = ' '.join(text_words)
wc = WordCloud(font_path='/fonts/msyh.ttc',background_color='white',width=1000,height=600).generate(content)
wc.to_file('词云图.png')
